package edu.npu.GraphIndex;

import java.util.Map;
import java.util.Queue;

//广度优先遍历,完成索引的建立以及距边界距离的计算
public class DistanceInit implements Traversable {
	int part;
	Map<Long, Integer> distance;
	Queue<Long> queue;
	Map<Long, Integer> partition;
	
	public DistanceInit(Queue<Long> queue, Map<Long, Integer> distance, Map<Long, Integer> partition, int part) {
		this.queue = queue;
		this.distance = distance;
		this.partition = partition;
		this.part = part;
	}
	
	@Override
	public boolean isTraversed(long node) {
		if(distance.containsKey(node))
			return true;
		return false;
	}

	@Override
	public void action(long node, int level) {
		if(partition.get(node) == part)
			distance.put(node, level);
		else
			distance.put(node, level + 1);
	}

	@Override
	public boolean isDone(int level) {
		if(queue.isEmpty())
			return true;
		return false;
	}
	
}
